<template>
  <div>
    <puplic-modal
      width="500px"
      :publicVisible="publicVisible"
      modalStyle="addEditSupportModal"
      @cancel="cancel"
      @handleOk="handleOk"
      :title="title"
    >
      <div slot="content" class="content">
        <div class="search-group" style="width: 100%">
          <div class="input-wrap" style="width: 100%">
            <div class="label">类别名称:</div>
            <div class="input-item" style="width: 100%">
              <a-input :maxLength="30" clearable v-model="examineCategoryName" placeholder="请输入类别名称" />
            </div>
          </div>
        </div>

        <div class="search-group" style="width: 100%">
          <div class="input-wrap" style="width: 100%">
            <div class="label">排序值:</div>
            <div class="input-item" style="width: 100%">
              <a-input :maxLength="5" clearable v-model="categoryNo" placeholder="请输入排序值,值越小排名越靠前" />
            </div>
          </div>
        </div>
      </div>
    </puplic-modal>
  </div>
</template>
<script>
import puplicModal from '@/components/publicModal'
import { examineCategoryAdd, examineCategoryEdit } from '@/api/industry'
export default {
  components: { puplicModal },
  name: 'addEditSupportModal',
  data() {
    return {
      title: '新增检查类别',
      publicVisible: false,
      categoryNo: '',
      examineCategoryName: '',
    }
  },
  mounted() {},
  methods: {
    show(records) {
      this.records = records
      this.industryExamineId = records.id
      this.industryInformationId = records.industryInformationId

      this.title = '新增检查类别'
      // if (records && records.id) {
      //   this.title = '编辑检查类别'
      //   this.categoryNo = records.categoryNo
      //   this.examineCategoryName = records.examineCategoryName
      // } else {
      //   this.title = '新增检查类别'
      // }
      this.publicVisible = true
    },

    async handleOk() {
      if (this.examineCategoryName == '') {
        this.$message.warn('请输入类别名称')
        return
      }
      if (this.categoryNo == '') {
        this.$message.warn('请输入排序值')
        return
      }
      let reg = /^(0|\+?[1-9][0-9]{0,4})$/
      if (reg.test(this.categoryNo) == false) {
        this.$message.warn('只支持输入小于五位的正整数')
        return
      }

      let data = {
        categoryNo: this.categoryNo,
        industryExamineId: this.industryExamineId,
        examineCategoryName: this.examineCategoryName,
        industryInformationId: this.industryInformationId,
      }
      if (this.title == '新增检查类别') {
        let res = await examineCategoryAdd(data)
        this.$message.success(res.message)
        this.cancel()
        this.$emit('refresh')
      } else {
        data.id = this.records.id
        let res = await examineCategoryEdit(data)
        this.$message.success(res.message)
        this.cancel()
        this.$emit('refresh')
      }
    },
    cancel() {
      this.categoryNo = ''
      this.examineCategoryName = ''
      this.publicVisible = false
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/common.less';

/deep/ .content {
  padding: 20px;
}
.search-group {
  padding: 0;
}
</style>
